//
//  HWBookTicketView.m
//  嗨文
//
//  Created by 响当当 on 2019/2/22.
//  Copyright © 2019年 dongzheng. All rights reserved.
//

#import "HWBookTicketView.h"
#import "HWBookTicketHeadView.h"
#import "HWBookTicketCell.h"
#import "HWRechargeNotesViewController.h"

@interface HWBookTicketView()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong)UITableView *tableView;

@property (nonatomic, strong)HWBookTicketHeadView *headView;

@end

@implementation HWBookTicketView

- (UITableView *)tableView
{
    if (!_tableView)
    {
        _tableView = [[UITableView alloc]initWithFrame:self.bounds style:UITableViewStylePlain];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.separatorStyle = 0;
        _tableView.tableHeaderView = self.headView;
    }
    return _tableView;
}

- (HWBookTicketHeadView *)headView
{
    if (!_headView)
    {
        _headView = [[HWBookTicketHeadView alloc]initWithFrame:CGRectMake(0,0,SCREEN_WIDTH,266*kUIScaleBasePlus)];
    }
    return _headView;
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        [self addSubview:self.tableView];
    }
    
    return self;
}

#pragma mark - tableView Delegate datasource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 2;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 56*kUIScaleBasePlus;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    HWBookTicketCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HWBookTicketCell"];
    if (!cell)
    {
        cell = [[HWBookTicketCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"HWBookTicketCell"];
        cell.selectionStyle = 0;
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }
    
    if (indexPath.row == 0)
    {
        [cell getDate:@"充值记录"];
    }
    else
    {
        [cell getDate:@"消费记录"];
    }
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    HWRechargeNotesViewController *vc = [[HWRechargeNotesViewController alloc]init];
    vc.hidesBottomBarWhenPushed = YES;
    vc.type = [NSString stringWithFormat:@"%ld",indexPath.row];
    [[HWUtilties getCurrentVC].navigationController pushViewController:vc animated:YES];
}

- (void)getBookToken:(NSDictionary *)dic
{
    [self.headView geyDate:dic];
}
@end
